# Copyright (c) 2021-2025 HPMicro
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required(VERSION 3.13)

set(CONFIG_CHERRYUSB 1)
set(CONFIG_USB_DEVICE 1)
set(CONFIG_USB_DEVICE_RNDIS 1)
set(CONFIG_LWIP 1)
set(CONFIG_LWIP_STRERR 1)
set(CONFIG_LWIP_NETDB 1)
set(CONFIG_LWIP_SOCKET_API 1)
set(CONFIG_LWIP_HTTPSRV 1)
set(CONFIG_FREERTOS 1)
set(CONFIG_EEPROM_EMULATION 1) 

if("${HPM_BUILD_TYPE}" STREQUAL "")
    SET(HPM_BUILD_TYPE flash_xip)
endif()

find_package(hpm-sdk REQUIRED HINTS $ENV{HPM_SDK_BASE})
project(web_server)

sdk_inc(src)
sdk_inc(common)
sdk_inc(common/config)
sdk_inc(common/arch)
sdk_inc(common/dhcp-server)
sdk_inc(common/dns-server)
sdk_inc(common/mongoose)
sdk_inc(common/ethercat/SSC/Src)
sdk_inc(common/ethercat/port)

sdk_app_src(src/main.c)
sdk_app_src(src/cdc_rndis_device.c)
sdk_app_src(src/net.c)
sdk_app_src(src/packed_fs.c)
sdk_app_src(src/board_ex.c)
sdk_app_src(src/digital_io.c)

sdk_app_src(common/arch/sys_arch.c)
sdk_app_src(common/dhcp-server/dhserver.c)
sdk_app_src(common/dns-server/dnserver.c)
sdk_app_src(common/mongoose/mongoose.c)
sdk_src(common/ethercat/SSC/Src/coeappl.c)
sdk_src(common/ethercat/SSC/Src/ecatappl.c)
sdk_src(common/ethercat/SSC/Src/ecatcoe.c)
sdk_src(common/ethercat/SSC/Src/ecatslv.c)
sdk_src(common/ethercat/SSC/Src/mailbox.c)
sdk_src(common/ethercat/SSC/Src/objdef.c)
sdk_src(common/ethercat/SSC/Src/sdoserv.c)
sdk_src(common/ethercat/port/hpm_ecat_hw.c)
sdk_src(common/ethercat/port/hpm_ecat_phy.c)
sdk_src(common/ethercat/port/hpm_ecat_e2p_emulation.c)

sdk_compile_definitions(-DUSE_NONVECTOR_MODE=1)
sdk_compile_definitions(-DDISABLE_IRQ_PREEMPTIVE=1)

generate_ide_projects()
